<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>客户编辑</title>
<link href="/resources/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="/resources/lib/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<script src="/resources/lib/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="/resources/lib/ligerUI/js/ligerui.all.js" type="text/javascript"></script>
<!-- <script src="/resources/lib/ligerUI/js/plugins/ligerForm.js" type="text/javascript"></script> -->
<script src="/resources/lib/jquery-validation/jquery.validate.min.js" type="text/javascript"></script> 
<script src="/resources/lib/jquery-validation/jquery.metadata.js" type="text/javascript"></script>
<script src="/resources/lib/jquery-validation/messages_cn.js" type="text/javascript"></script>
<script src="/resources/lib/json2.js" type="text/javascript"></script>
<script src="/resources/js/jsF7.js" type="text/javascript"></script>
<script src="/resources/js/selectData.js" type="text/javascript"></script>
<script src="/resources/js/themis.js" type="text/javascript"></script>
<script src="/resources/js/validation.js" type="text/javascript"></script>
<style type="text/css">
    .l-table-edit {}
    .l-table-edit-td-label{width: 100px;padding-top: 5px;}
    .l-table-edit-td-input{width: 200px;padding-top: 5px;}
    .div-buttom{position: absolute;top:380px;}
    
</style>
<script type="text/javascript">
var form1 = null;
var toolbar = null;
var info = '${info}';
var existCustomer = null;
if(info){
	existCustomer = JSON.parse(info); 
}
var status = '${status}';
var number = '${number}';
var supplierClassificationUuid ='${supplierClassificationUuid}';
 
$(function (){
    //工具条
    toolbar = $("#toptoolbar").ligerToolBar({ items: [
        { text: '保存', id:'save',click: saveForm,icon: 'save' }
    ]
    });
  //创建表单(头部)
    form1 = $("#form1").ligerForm({
    inputWidth: 170, labelWidth: 90, space: 40,
    validate:true,
    fields: [
        { name: "uuid", type: "hidden" },
        { name: "createUser.uuid", type: "hidden" },
        { name: "createDate", type: "hidden" },
        { display: "编号", name: "number", type: "text",newline: false, validate: {remote:{type:"POSt",url:"/supplier/checkNumberUsed",
      	  data:{uuid:function(){
        	  var uuidEd = form1.getEditor("uuid"); //form中应用
              var uuid = uuidEd.val();
        	  return uuid;
        	  }}},required: true,minlength: 1},validateMessage:{remote:"此编码已经存在"} },
        { display: "名称", name: "name", type: "text",newline: false,  validate: { required: true} },
        { display: "供应商分类", name: "supplierClassification.uuid", newline: false, type: "popup",textField:"supplierClassification.name",validate: { required: true},
      	   editor: {
                 grid: getSupplierClassificationGrid(true),
                 valueField:'uuid',
                 textField: 'name',
                 parms :{leaf:'1',date:new Date().getTime()},
                 width: 300,
                 height:100,
                 realTimeLoad:true
        	 }
         },
         { display: "所属采购员", name: "subBuyer.uuid", newline: false,group: "基础信息", type: "popup",textField:"subBuyer.trueName",
			   editor: {
		        grid: getSysUserGrid(true),
		        valueField:'uuid',
		        textField: 'trueName',
		        parms :{date:new Date().getTime()},
		        width: 300,
		        height:100,
		        realTimeLoad:true
			 }   
		},
 /* { display: "业务分析码", name: "businessNum", newline: false, type: "text"}, */
 /* { display: "内部供应商", name: "inerCustomer", newline: false, type: "text"},
 { display: "内部公司", name: "inerCompany", newline: false, type: "text"},
 { display: "上级供应商", name: "superCustomer", newline: false, type: "text"}, */
/*  { display: "供应商性质", name: "supplierProper", newline: false, type: "text"}, */
/*   { display: "供应商性质", name: "supplierProper.uuid", newline: false, type: "popup",textField:"supplierProper.name",
	   editor: {
         grid: getSuppliersNatureGrid(true),
         valueField:'uuid',
         textField: 'name',
         parms :{date:new Date().getTime()},
         width: 300,
         height:100,
         realTimeLoad:true
	 }   
 }, *///Nature of the supplier
 { display: "供应商性质", name: "supplierNature", newline: false,  type: "select",editor: {data:supplier_nature_data,cancelable:false,initValue:"supplier",valueField: 'value',textField: 'text',
		onSelected  :function(value,text){
			/* if(form1){
				if(value == "false"){
					 var barCode = form1.getEditor("barCode"); //form中应用
					 barCode.setValue(null);
					 form1.setFieldValidate("barCode",{required:false},{});
             	  
             	  form1.setEnabled(["barCode"],false);
				}else if(value == "true"){
					form1.setFieldValidate("barCode",{required: true},{});
					 form1.setEnabled(["barCode"],true);
				}
			} */
		}
	}}, 
 { display: "工商注册号", name: "industrialNum", newline: false, type: "text"},
 { display: "营业执照", name: "tradingNum", newline: false, type: "text"},
 { display: "经营许可证", name: "manageNum", newline: false, type: "text"},
 { display: "税务登记号", name: "taxNumber", newline: false, type: "text"},
 { display: "法人代表", name: "legalPerson", newline: false, type: "text"},
 { display: "行业", name: "industry", newline: false, type: "text"},
 { display: "国家", name: "country", newline: false, type: "select",editor: {}},
 { display: "省份", name: "province", newline: false, type: "select",editor: {}},
 { display: "城市(区)", name: "city", newline: false, type: "select",editor: {}},
 { display: "地区(县)", name: "district", newline: false, type: "select",editor: {}},
 { display: "邮政编码", name: "zipCode", newline: false, type: "text"},
 { display: "税种", name: "taxType", newline: false, type: "text"},
 { display: "税率", name: "taxRate", newline: false, type: "text"},
/*   { display: "开票类型", name: "makeType", newline: false, type: "text"}, */
 { display: "开票类型", name: "makeType", newline: false,  type: "select",editor: {data:billing_type,
		valueField: 'value',textField: 'text'
	}},
 { display: "地址", name: "address", newline: true, type: "text",width:470},
 
 { display: "会计联系人", name: "finance.accountingPerson", group:'财务资料', newline: false, type: "text"}, 
	{ display: "联系人职务", name: "finance.personPosition", newline: false, type: "text"}, 
	{ display: "办公电话", name: "finance.phone", newline: false, type: "text"}, 
	{ display: "手机", name: "finance.mobile", newline: false, type: "text"}, 
	/* { display: "邮件", name: "finance.mail", newline: false, type: "text"},  */
	/* { display: "开户银行", name: "finance.openBank", newline: false, type: "text"}, */
	{ display: "开户银行", name: "finance.openBank.uuid", newline: false, type: "popup",textField:"finance.openBank.name",
 	   editor: {
            grid: getBankGrid(true),
            valueField:'uuid',
            textField: 'name',
            parms :{date:new Date().getTime()},
            width: 300,
            height:100,
            realTimeLoad:true
   	 }   
  },
	{ display: "银行账号", name: "finance.bankAccount", newline: false, type: "text"},
	/* { display: "币别", name: "finance.currency", newline: false, type: "text"}, */
	{ display: "币别", name: "finance.currency.uuid", newline: false, type: "popup",textField:"finance.currency.name",
 	   editor: {
            grid: getCurrencyGrid(true),
            valueField:'uuid',
            textField: 'name',
            parms :{date:new Date().getTime()},
            width: 300,
            height:100,
            realTimeLoad:true
   	 }   
  },
	{ display: "账户名称", name: "finance.accountName", newline: false, type: "text"},
	
	{ display: "联系人", name: "pur.contactPerson", group:'采购资料', newline: false, type: "text"},
	{ display: "联系人职务", name: "pur.personPosition", newline: false, type: "text"},
	{ display: "办公电话", name: "pur.phone", newline: false, type: "text"},
	{ display: "手机", name: "pur.mobile", newline: false, type: "text"},
	{ display: "邮件", name: "pur.mail", newline: false, type: "text"},
	{ display: "传真", name: "pur.fax", newline: false, type: "text"},
	{ display: "邮政编码", name: "pur.zipCode", newline: false, type: "text"},
	{ display: "联系地址", name: "pur.address", newline: true, type: "text",width:470}
        ]
    });
  if(existCustomer){
	  form1.setData(existCustomer);
  }else{
	  if(number){
		  var numberE = form1.getEditor("number"); //form中应用
		  numberE.setValue(number);
		 // form1.setData({number:number});
	  }
	  if(supplierClassificationUuid){
		  var e = form1.getEditor("supplierClassification.uuid"); //form中应用
		  e.setValue(supplierClassificationUuid,null);
	  }
  }
/*   if(number){
	  form1.setData({number:number});
  } */
  if(status && status =='1'){
	  toolbar.setDisabled('save');
	  form1.setAllEnabled(false);
  }
  citySelect({
	  countryEditers:[form1.getEditor("country")],
	  provEditers:[form1.getEditor("province")],
	  cityEditers:[form1.getEditor("city")],
	  distEditers:[form1.getEditor("district")],
  });
});

//保存
function saveForm(){
   // var forms = $('#form1').serialize(); 
    var data = form1.getData();
   /*  delete data.supplierProperName;
    delete data.finance.openBankName;
    delete data.finance.currencyName; */
   // data = JSON.stringify(data);
    console.log(data);
    if(form1.valid()){
	 	$.ajax({
	        loading: '正在保存数据中...',
	        type:'post',
	        url: "/supplier/saveOrUpdateSupplier",
			dataType:'json',
	        data: {supplier:JSON.stringify(data)},
	        success: function (data) {
					$.ligerDialog.success(data.message,'信息',function(){
						$("#uuid").val(data.data.uuid);
				    });
	        },
	        error: function (message) {
	       	 	$.ligerDialog.error("保存失败");
	        }
	    });
    }
}
</script>
</head>
<body>
	<div id="toptoolbar"></div>
	<form id="form1"></form>
</body>
</html>